#include "delge_squirrelinput.h"

void s_Input_RegisterFunctions (HSQUIRRELVM v)
{
	SquirrelVM::CreateFunctionGlobal(s_Input_GetMouseX,					_SC("GetMouseX"),						_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Input_GetMouseY,					_SC("GetMouseY"),						_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Input_GetCharacter,				_SC("GetCharacter"),					_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Input_FlushCharacters,			_SC("FlushCharacters"),					_SC(""));
	SquirrelVM::CreateFunctionGlobal(s_Input_IsMouseButtonUp,			_SC("IsMouseButtonUp"),					_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Input_IsMouseButtonDown,			_SC("IsMouseButtonDown"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Input_IsMouseButtonHit,			_SC("IsMouseButtonHit"),				_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Input_IsMouseButtonPressed,		_SC("IsMouseButtonPressed"),			_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Input_IsKeyUp,					_SC("IsKeyUp"),							_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Input_IsKeyDown,					_SC("IsKeyDown"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Input_IsKeyHit,					_SC("IsKeyHit"),						_SC("*"));
	SquirrelVM::CreateFunctionGlobal(s_Input_IsKeyPressed,				_SC("IsKeyPressed"),					_SC("*"));
}

SQInteger s_Input_GetMouseX	(HSQUIRRELVM v)
{
	sq_pushinteger			(v, Globals::pGame->GetEngine()->GetMouseX());

	return 1;
}

SQInteger s_Input_GetMouseY (HSQUIRRELVM v)
{
	sq_pushinteger			(v, Globals::pGame->GetEngine()->GetMouseY());

	return 1;
}

SQInteger s_Input_HasCharacterInput (HSQUIRRELVM v)
{
	//if (
	return 0;
}

SQInteger s_Input_GetCharacter (HSQUIRRELVM v)
{
	char				cCharacter;
	string				sCharacter;

	cCharacter = Globals::pGame->GetEngine()->GetChar();
	
	if (cCharacter != -1)
	{
		sCharacter = cCharacter;
		sq_pushstring (v, sCharacter.c_str(), -1);
		return 1;
	}
	
	return 0;
}

SQInteger s_Input_FlushCharacters (HSQUIRRELVM v)
{
	Globals::pGame->GetEngine()->FlushChar();

	return 0;
}

SQInteger s_Input_IsMouseButtonUp (HSQUIRRELVM v)
{
	SQInteger				eMouse;

	sq_getinteger			(v, 2, &eMouse);

	sq_pushbool				(v, Globals::pGame->GetEngine()->GetInput()->IsMouseButtonUp((MouseCode)eMouse));

	return 1;
}

SQInteger s_Input_IsMouseButtonDown (HSQUIRRELVM v)
{
	SQInteger				eMouse;

	sq_getinteger			(v, 2, &eMouse);

	sq_pushbool				(v, Globals::pGame->GetEngine()->GetInput()->IsMouseButtonDown((MouseCode)eMouse));

	return 1;
}

SQInteger s_Input_IsMouseButtonHit (HSQUIRRELVM v)
{
	SQInteger				eMouse;

	sq_getinteger			(v, 2, &eMouse);

	sq_pushbool				(v, Globals::pGame->GetEngine()->GetInput()->IsMouseButtonHit((MouseCode)eMouse));

	return 1;
}

SQInteger s_Input_IsMouseButtonPressed (HSQUIRRELVM v)
{
	SQInteger				eMouse;

	sq_getinteger			(v, 2, &eMouse);

	sq_pushbool				(v, Globals::pGame->GetEngine()->GetInput()->IsMouseButtonPressed((MouseCode)eMouse));

	return 1;
}

SQInteger s_Input_IsKeyUp (HSQUIRRELVM v)
{
	SQInteger				eKey;

	sq_getinteger			(v, 2, &eKey);

	sq_pushbool				(v, Globals::pGame->GetEngine()->GetInput()->IsKeyUp((KeyCode)eKey));

	return 1;
}

SQInteger s_Input_IsKeyDown (HSQUIRRELVM v)
{
	SQInteger				eKey;

	sq_getinteger			(v, 2, &eKey);

	sq_pushbool				(v, Globals::pGame->GetEngine()->GetInput()->IsKeyDown((KeyCode)eKey));

	return 1;
}

SQInteger s_Input_IsKeyHit (HSQUIRRELVM v)
{
	SQInteger				eKey;

	sq_getinteger			(v, 2, &eKey);

	sq_pushbool				(v, Globals::pGame->GetEngine()->GetInput()->IsKeyHit((KeyCode)eKey));

	return 1;
}

SQInteger s_Input_IsKeyPressed (HSQUIRRELVM v)
{
	SQInteger				eKey;

	sq_getinteger			(v, 2, &eKey);

	sq_pushbool				(v, Globals::pGame->GetEngine()->GetInput()->IsKeyPressed((KeyCode)eKey));

	return 1;
}